
<section class="content-header">
    <h1>
      义不容辞之事，当无怨无悔
      <small>乐乐的每日一句</small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> 文章管理</a></li>
      <li class="active">创建文章</li>
    </ol>
  </section>
  <!-- Main content -->
  <section class="content">
<div class="box box-info">
     <form class="form-horizontal" id="forms"> 
        <div class="box-body">
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">历程标题</label>
            <div class="col-sm-8">
              <input type="text" class="form-control" id="inputEmail3" name="title" placeholder="文章标题">
             <input style="height:0px;border:0px;margin:0px;padding:0px" id="userid" type="text" value=<%= id%> >
            </div>
          </div>
          <div class="form-group">
            <label class="col-sm-2 control-label">历程描述</label>
            <div class="col-sm-8">
                <textarea class="form-control" rows="3" placeholder="请输入文章的简短描述" name="desc" id="desc"></textarea>
              </div>
          </div>
         <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">历程开始时间</label>
           <div class="input-group col-sm-8" style="padding-left:15px !important;padding-right:15px !important">
            <div class="input-group-addon">
              <i class="fa fa-calendar"></i>
            </div>
            <input type="text" class="form-control pull-right" id="datepicker">
          </div>
          </div>
          <div class="form-group">
            <label for="inputEmail3" class="col-sm-2 control-label">历程结束时间</label>
           <div class="input-group col-sm-8" style="padding-left:15px !important;padding-right:15px !important">
            <div class="input-group-addon">
              <i class="fa fa-calendar"></i>
            </div>
            <input type="text" class="form-control pull-right" id="datepicker2">
          </div>
          </div>
        </div>
        <!-- /.box-body -->
        <div class="box-footer">
          <button type="button" class="btn btn-info pull-right" id="lanuchs"  onclick="submits('0')">保存</button>
         <button type="button" class="btn btn-warning pull-middle" id="lanuch"  onclick="submits('1')">发布</button>
        </div>
        <!-- /.box-footer -->
      </form>
</div>


</section>


<script type="text/javascript">


function submits (data){
                            $('#forms').data('bootstrapValidator').validate();//启用验证
                            var flag = $('#forms').data('bootstrapValidator').isValid()//验证是否通过true/false
                            if(flag){
                                projectMark = $('#userid').val()
                                title = $('#inputEmail3').val()
                                desc = $('#desc').val()
                                projectUrl = $('#projectUrl').val()
                                startTime=$('#datepicker').val()
                                startTime = new Date(startTime).getTime()
                                endTime=$('#datepicker2').val()
                                endTime = new Date(endTime).getTime()
                                $.post(localhost+"/exprience/exprienceAction", { //jq的post方法
                                    projectTitle:title,
                                    projectDesc: desc,
                                    status:data,
                                    startTime:startTime,
                                    endTime:endTime,
                                    projectMark:projectMark
                                }, function(res) {
                                    swal.fire({
                                        type: res.type,
                                        title: res.message
                                    })
                                    .then((value) => {
                                            switch (value) {
                                                default:
                                                if(res.type =='success'){
                                                    // window.location.replace(localhost+"/manarticle");
                                                    $('.content-wrapper').load(localhost + "/exprience");
                                                }
                                            }
                                            }
                                        );
                                    if(res.type =='success'){
                                        // window.location.replace(localhost+"/manarticle");
                                    }
                                   
                                })
                            }else{
                                Toast.fire({
                                        type: 'info',
                                        title: '请完善文章信息'
                                    })
                            }
                        };
 const Toast = Swal.mixin({
      toast: true,
      position: 'middle',
      showConfirmButton: false,
      timer: 3000
    });
$(document).ready(function() {              
    $(".select2").select2();
    $('#datepicker').datepicker({
      autoclose: true
    });
    $('#datepicker2').datepicker({
      autoclose: true
    });
    $('#forms').bootstrapValidator({
      message: 'This value is not valid',
         feedbackIcons: {
             valid: 'glyphicon glyphicon-ok',
             invalid: 'glyphicon glyphicon-remove',
             validating: 'glyphicon glyphicon-refresh'
         },
      
      fields: {
        title: {
                validators: {  
                      notEmpty: {                        
                        message: '请填写文章名'                     
                      }
                                   
                    }             
                },
        inputName: {
          validators: {  
            notEmpty: {                        
                    message: '请填写文章内容'                     
                  }   
            }   
          },
        //   logo: {
        //   validators: {  
        //     notEmpty: {                        
        //             message: '请添加文章封面'                     
        //           }   
        //     }   
        //   },
          desc: {
            validators: {  
                  notEmpty: {                        
                    message: '请填写文章描述'                     
                  }

                }             
            },
            kind: {
            validators: {  
                  notEmpty: {                        
                    message: '请填写文章分类'                     
                  }
            }
      }
    }
    })
     

function getCookie(cookie_name) {
        var stringResult = '<%= id%>'.split(';');
        console.log(stringResult[2])
        var allcookies = document.cookie;
		//索引长度，开始索引的位置
        var cookie_pos = allcookies.indexOf(cookie_name);

        // 如果找到了索引，就代表cookie存在,否则不存在
        if (cookie_pos != -1) {
            // 把cookie_pos放在值的开始，只要给值加1即可
            //计算取cookie值得开始索引，加的1为“=”
            cookie_pos = cookie_pos + cookie_name.length + 1; 
            //计算取cookie值得结束索引
            var cookie_end = allcookies.indexOf(";", cookie_pos);
            
            if (cookie_end == -1) {
                cookie_end = allcookies.length;

            }
            //得到想要的cookie的值
            var value = unescape(allcookies.substring(cookie_pos, cookie_end)); 
        }
        return value;
    }

                 
                   
                

$("#forms").submit(function(e){ //uploadVideoForm为表单名称
   e.preventDefault()
});
          
function imgSrcToBase64(img) {
    var canvas = document.createElement("canvas");
    canvas.width = img.width;
    canvas.height = img.height;
    var ctx = canvas.getContext("2d");
    ctx.drawImage(img,0,0,img.width,img.height);
    return canvas.toDataURL();
}
});
</script>



  